/*
 * Playlist keeps track of all the songs that the user has added and picks
 * the correct one when the user requests a song to be played.
 */

import java.awt.Component;
import java.io.File;
import java.util.ArrayList;

import javazoom.jlgui.basicplayer.BasicController;
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;
import javazoom.jlgui.basicplayer.BasicPlayerListener;

/* 
 * A playlist holds songs
 */

public class Playlist {
	ArrayList songList = new ArrayList<Song>();
	
	/*
	 * Adds a song to the playlist
	 */
	
	public void addSong (Song newSong) {
		this.songList.add(newSong);
	}
	
	public ArrayList<Song> getPlaylist () {
		return this.songList;
	}
	
	/*
	 * Finds the song from the current playlist and plays it
	 */
	
	public void playSong (int i, CurrentListener nowPlaying, BasicPlayer player) {
		ArrayList<Song> songList = getPlaylist();
		Song song = (Song) songList.get(i);
		String songPath = song.getFilePath();
		nowPlaying.playSong(songPath, player);
	}
	
	/*
	 * Plays the next song in the playlist, if there is one
	 */
	
	public boolean playNextSong (int i, CurrentListener nowPlaying, BasicPlayer player) {
		ArrayList<Song> songList = getPlaylist();
		if ((Song) songList.get(i+1) != null) {
			playSong (i+1, nowPlaying, player);
			return true;
		}
		else
			return false;
	}
	
	/*
	 * Plays the previous song in the playlist, if there is one
	 */
	
	public boolean playPreviousSong (int i, CurrentListener nowPlaying, BasicPlayer player) {
		ArrayList<Song> songList = getPlaylist();
		if ((Song) songList.get(i-1) != null) {
			playSong (i-1, nowPlaying, player);
			return true;
		}
		else
			return false;
	}
	
	/*
	 * Plays the first song in the playlist, if there is one
	 */
	
	public boolean playFirstSong (CurrentListener nowPlaying, BasicPlayer player) {
		ArrayList<Song> songList = getPlaylist();
		if ((Song) songList.get(0) != null) {
			playSong (0, nowPlaying, player);
			return true;
		}
		else
			return false;
	}
}
